package com.zhuangxiaoyan.spring.transaction.sevice;

import com.zhuangxiaoyan.spring.transaction.entity.Account;
import com.zhuangxiaoyan.spring.transaction.dao.AccountService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname AccountServiceImpl
 * @Description TODO
 * @Date 2022/5/3 10:30
 * @Created by xjl
 */
@Service
@Transactional(propagation = Propagation.NEVER)
public class AccountServiceImpl2 implements AccountService2 {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int update(Account account) {
        String sql = "update account set money = ? where id = ?";

        List<Object> list = new ArrayList<>();
        list.add(account.getMoney());
        list.add(account.getId());
        return jdbcTemplate.update(sql,list.toArray());
    }

    @Override
    public int delete(int id) {
        String sql = "delete from account where id = ?";
        jdbcTemplate.update(sql,id);
        return 0;
    }
}
